//
//  DKTabBarController.m
//  BS1
//
//  Created by 丁侃 on 16/4/23.
//  Copyright © 2016年 丁侃. All rights reserved.
//

#import "DKTabBarController.h"
#import "DKPublishViewController.h"
#import "DKNewViewController.h"
#import "DKMeViewController.h"
#import "DKFriendThrendsViewController.h"
#import "DKEssenceViewController.h"

#import "DKTabBar.h"
#import "DKNavigationController.h"



@interface DKTabBarController ()

@end

@implementation DKTabBarController



+(void)initialize
{
    
    //设置tabBarItem的字体属性
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    NSDictionary *dicN = @{
                           NSFontAttributeName:[UIFont systemFontOfSize:14.0],
                           NSForegroundColorAttributeName: [UIColor grayColor]
                           };
    [item setTitleTextAttributes:dicN forState:UIControlStateNormal];
    
    NSDictionary *dicS = @{
                           NSFontAttributeName:[UIFont systemFontOfSize:14.0],
                           NSForegroundColorAttributeName:[UIColor darkGrayColor]
                           };
    
    [item setTitleTextAttributes:dicS forState:UIControlStateSelected];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //添加自控制器
    [self setupChildControllers];
    
    DKTabBar *tabBar = [[DKTabBar alloc]init];
    
    [self setValue:tabBar forKeyPath:@"TabBar"];
    
    tabBar.publichBlock = ^{
    
            DKFunc
    };
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

}


//添加自控制器
-(void)setupChildControllers
{
    //添加首页
    DKEssenceViewController *essence = [[DKEssenceViewController alloc]init];
    [self setupOneChildController:essence withImageNanme:@"tabBar_essence_icon" withSelectedImageNanme:@"tabBar_essence_click_icon" withTabBarTitle:@"首页" withNavTitle:@"首页"];
    
    //new
    DKNewViewController *new = [[DKNewViewController alloc]init];
    [self setupOneChildController:new withImageNanme:@"tabBar_new_icon" withSelectedImageNanme:@"tabBar_new_click_icon" withTabBarTitle:@"new" withNavTitle:@"new"];
    
    
    //friendThrends
    DKFriendThrendsViewController *friendThrends = [[DKFriendThrendsViewController alloc]init];
    [self setupOneChildController:friendThrends withImageNanme:@"tabBar_friendTrends_icon" withSelectedImageNanme:@"tabBar_friendTrends_click_icon" withTabBarTitle:@"关注" withNavTitle:@"我的关注"];
    
    
    //me
    DKMeViewController *me = [[DKMeViewController alloc]init];
    [self setupOneChildController:me withImageNanme:@"tabBar_me_icon" withSelectedImageNanme:@"tabBar_me_click_icon" withTabBarTitle:@"我" withNavTitle:@"我的"];
}

//添加一个自控制器
-(void)setupOneChildController:(UIViewController *) controller withImageNanme:(NSString *) image withSelectedImageNanme:(NSString *)selImage withTabBarTitle:(NSString *)tabBartitle withNavTitle:(NSString *)navTitle
{
    DKNavigationController *nav = [[DKNavigationController alloc]initWithRootViewController:controller];
    controller.navigationItem.title = navTitle;
    nav.tabBarItem.title = tabBartitle;
    
    if (image.length > 0) {
        nav.tabBarItem.image = [UIImage imageNamed:image];
    }
    if (selImage.length > 0) {
        nav.tabBarItem.selectedImage = [UIImage imageNamed:selImage];
    }
    [self addChildViewController:nav];
}


@end
